package net.arvin.dao;

import java.util.List;
import java.util.Map;

import net.arvin.mobilebanksystem.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

public class DialogListAdapter extends BaseAdapter implements ListAdapter {
	private List<Map<String, String>> data;
	private LayoutInflater mInflater;

	public static final String MONEY_KEY = "money";
	public static final String PRICE_KEY = "price";
	public static final String ISSELECT = "isselect";

	public DialogListAdapter(Context context, List<Map<String, String>> data) {
		this.data = data;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listitem_dialog, null);
			holder = new ViewHolder();
			holder.money = (TextView) convertView
					.findViewById(R.id.recharge_money);
			holder.price = (TextView) convertView
					.findViewById(R.id.recharge_price);
			holder.select = (ImageView) convertView.findViewById(R.id.isSelect);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.money.setText(data.get(position).get(MONEY_KEY));
		holder.price.setText(data.get(position).get(PRICE_KEY));
		holder.select.setImageResource(R.drawable.not_select);
		if (data.get(position).get(ISSELECT).equals("1")) {
			holder.select.setImageResource(R.drawable.select);
		}
		return convertView;
	}

	public class ViewHolder {
		public TextView money;
		public TextView price;
		public ImageView select;
	}

}
